package com.sbs.gaoxinqutoilet.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.sbs.gaoxinqutoilet.R;
import com.sbs.gaoxinqutoilet.entity.HomeNewsEntity;

import java.util.List;

/**
 * Created by 聪明一只哈 on 2019/10/29.
 * Time: 2019/10/29  15:25
 */
public class HotAdapter extends DelegateAdapter.Adapter {

    private Context mContext;
    private LayoutHelper mLayoutHelper;
    private List<HomeNewsEntity.DataBean> mItemChanelList;
    private LayoutInflater inflater;

    public HotAdapter(Context mContext, LayoutHelper mLayoutHelper, List<HomeNewsEntity.DataBean> mItemChanelList) {
        this.mContext = mContext;
        this.mLayoutHelper = mLayoutHelper;
        this.mItemChanelList = mItemChanelList;
        inflater = LayoutInflater.from(mContext);

    }

    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return mLayoutHelper;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new RecommandViewHolder(inflater.inflate(R.layout.vlayout_hot_view,viewGroup,false));
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
        RecommandViewHolder holder= (RecommandViewHolder) viewHolder;

        final HomeNewsEntity.DataBean recommendInfoBean = mItemChanelList.get(i);

        holder.tv_name.setText(recommendInfoBean.getNews_title());
        holder.tv_price.setText(recommendInfoBean.getOpt_time());

        holder.ll_hot.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(recomAdapterClicker!=null){
                    recomAdapterClicker.callBack(recommendInfoBean);
                }
            }
        });

    }

    @Override
    public int getItemCount() {
        return mItemChanelList==null?0:mItemChanelList.size();
    }

    static class RecommandViewHolder extends RecyclerView.ViewHolder{

        private TextView tv_name;
        private TextView tv_price;
        private LinearLayout ll_hot;
        public RecommandViewHolder(@NonNull View itemView) {
            super(itemView);

            tv_name=(TextView) itemView.findViewById(R.id.tv_name);
            tv_price=(TextView) itemView.findViewById(R.id.tv_price);
            ll_hot=(LinearLayout) itemView.findViewById(R.id.ll_hot);
        }
    }

    private HotAdapterClicker recomAdapterClicker;

    public interface HotAdapterClicker{
        void callBack(HomeNewsEntity.DataBean hotInfoBean);
    }

    public void setHotAdapterClicker(HotAdapterClicker recomAdapterClicker){
        this.recomAdapterClicker=recomAdapterClicker;
    }

}
